package org.lionsoul.ip2region.txt;

public class IPMergeArea {

    private final static String UNKNOWN = "0";
    String start;
    String end;
    // country or state
    String country;
    String province;
    String city;

    public IPMergeArea(String raw) {
        String[] content = raw.split("\\|");
        start = content[0];
        end = content[1];
        country = UNKNOWN.equals(content[2]) ? null : content[2];
        province = UNKNOWN.equals(content[4]) ? null : content[4];
        city = UNKNOWN.equals(content[5]) ? null : content[5];
    }

    @Override
    public String toString() {
        return country + '|' +
           province + '|' +
           city;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof IPMergeArea) {
            return this.city.equals(((IPMergeArea) obj).city)
                && this.province.equals(((IPMergeArea) obj).province)
                && this.country.equals(((IPMergeArea) obj).country);
        }
        return super.equals(obj);
    }
}
